package com.ruoyi.project.wechatprogram.evaluation.controller;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.project.wechatprogram.ordermaster.controller.WxOrderMasterController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wechatprogram.evaluation.domain.WxEvaluation;
import com.ruoyi.project.wechatprogram.evaluation.service.IWxEvaluationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 意见反馈留言Controller
 * 
 * @author sxchen
 * @date 2020-04-21
 */
@Controller
@RequestMapping("/wechatprogram/evaluation")
public class WxEvaluationController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(WxEvaluationController.class);

    private String prefix = "wechatprogram/evaluation";

    @Autowired
    private IWxEvaluationService wxEvaluationService;

    @RequiresPermissions("wechatprogram:evaluation:view")
    @GetMapping()
    public String evaluation()
    {
        return prefix + "/evaluation";
    }

    /**
     * 查询意见反馈留言列表
     */
    @RequiresPermissions("wechatprogram:evaluation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxEvaluation wxEvaluation)
    {
        startPage();
        List<WxEvaluation> list = wxEvaluationService.selectWxEvaluationList(wxEvaluation);
        return getDataTable(list);
    }

    /**
     * 查询意见反馈留言列表
     */
    @PostMapping("/wxlist")
    @ResponseBody
    public AjaxResult wxlist(WxEvaluation wxEvaluation)
    {
        startPage();
        List<WxEvaluation> list = wxEvaluationService.selectWxEvaluationList(wxEvaluation);
        return AjaxResult.success(list);
    }

    /**
     * 导出意见反馈留言列表
     */
    @RequiresPermissions("wechatprogram:evaluation:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxEvaluation wxEvaluation)
    {
        List<WxEvaluation> list = wxEvaluationService.selectWxEvaluationList(wxEvaluation);
        ExcelUtil<WxEvaluation> util = new ExcelUtil<WxEvaluation>(WxEvaluation.class);
        return util.exportExcel(list, "evaluation");
    }

    /**
     * 新增意见反馈留言
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意见反馈留言
     */
    @Log(title = "意见反馈留言", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxEvaluation wxEvaluation)
    {
        if(StrUtil.isBlankIfStr(wxEvaluation)){
            return AjaxResult.error("留言内容不能为空！！！");
        }

        wxEvaluationService.insertWxEvaluation(wxEvaluation);
        return AjaxResult.success("留言成功");
}

    /**
     * 修改意见反馈留言
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WxEvaluation wxEvaluation = wxEvaluationService.selectWxEvaluationById(id);
        mmap.put("wxEvaluation", wxEvaluation);
        return prefix + "/edit";
    }

    /**
     * 修改保存意见反馈留言
     */
    @RequiresPermissions("wechatprogram:evaluation:edit")
    @Log(title = "意见反馈留言", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxEvaluation wxEvaluation)
    {
        return toAjax(wxEvaluationService.updateWxEvaluation(wxEvaluation));
    }

    /**
     * 删除意见反馈留言
     */
    @RequiresPermissions("wechatprogram:evaluation:remove")
    @Log(title = "意见反馈留言", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxEvaluationService.deleteWxEvaluationByIds(ids));
    }
}
